<?php
class Mwc_SystemPoint_Block_Membership_List_Grid extends Mage_Adminhtml_Block_Widget_Grid{
    public function __construct(){
        parent::__construct();
        $this->setId('membershipGrid');
        $this->_controller = 'systempoint';
    }

    protected function _prepareCollection(){
        $model = Mage::getModel('systempoint/membership');
        $collection = $model->getCollection();
        $this->setCollection($collection);

        return parent::_prepareCollection();
    }

    protected function _prepareColumns(){
        $this->addColumn('title', array(
            'header'        => Mage::helper('systempoint')->__('Level'),
            'align'         => 'left',
            'filter_index'  => 'title',
            'index'         => 'title',
        ));

        $this->addColumn('number_of_point', array(
            'header'    	=> Mage::helper('systempoint')->__('Number of point'),
            'align'         => 'left',
            'filter_index'  => 'number_of_point',
            'index'    	 	=> 'number_of_point',
            'width'         => '150px',
        ));

        $this->addColumn('percent_discount', array(
            'header'    	=> Mage::helper('systempoint')->__('Percent discount'),
            'align'         => 'left',
            'filter_index'  => 'percent_discount',
            'index'    	 	=> 'percent_discount',
            'width'         => '150px',
        ));

        $this->addColumn('icon_path', array(
            'header'    	=> Mage::helper('systempoint')->__('Icon'),
            'align'         => 'left',
            'filter'        => false,
            'index'    	 	=> 'icon_path',
            'sortable'      => false,
          	'renderer'  => 'systempoint/membership_image_render'
        ));

        $this->addColumn('action',
            array(
                'header'    => Mage::helper('systempoint')->__('Action'),
                'width'     => '150px',
                'type'      => 'action',
                'getter'	=> 'getMembershipId',
                'actions'   => array(
                    array(
                        'caption' => Mage::helper('systempoint')->__('Edit'),
                        'url'     => array(
                            'base'=>'*/*/edit'
                        ),
                        'field'   => 'id'
                    ),
                    array(
                        'caption' => Mage::helper('systempoint')->__('Delete'),
                        'url'     => array(
                            'base'=>'*/*/delete'
                        ),
                        'field'   => 'id'
                    )
                ),
                'filter'    => false,
                'sortable'  => false
            ));

        return parent::_prepareColumns();
    }

    public function getRowUrl($row){
        return $this->getUrl('*/*/edit', array(
            'id' => $row->getMembershipId(),
        ));
    }
}